import {showAll,showById} from '../service/user'
export default {
    namespaced:true,
    state:{
        token:"",
        userId:'',
        users:[],
        updateVisible:false,
        updateAddRoleVisible:false,
        user:{},
        pagination:{
        }
    },
    mutations:{
        setUserId(state,userId){
            state.userId = userId;
        },
        setToken(state,token){
            state.token = token
        },
        setUsers(state,users){
            state.users = users;
        },
        setPagination(state,pagination){
            state.pagination = pagination;
        },
        setUser(state,user){
            state.user = user;
        },
        setUpdateVisible(state,updateVisible){
            state.updateVisible = updateVisible;
        },
        setUpdateAddRoleVisible(state,updateAddRoleVisible){
            state.updateAddRoleVisible = updateAddRoleVisible;
        }
    },
    actions:{
        async setUsers({commit},obj={}){
            
            let data = await showAll(obj.page,obj.size);
            console.log("data:",data)
            if(data.status != 1){
                commit("setUsers",[]);
                commit("setPagination",{});
            }else{
                commit("setUsers",data.data.records);
                commit("setPagination",data.data);
            }
        },
        async setUser({commit},userId){
            
            let data = await showById(userId);
            commit("setUser",data.data);
        }
    }
}